﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Net;
using System.IO;
using System.Web.Script.Serialization;
using PiscoSourDominio;
using System.Text; 

namespace PiscoSourWeb.Models
{
    public class ModelCartaLocal: IDisposable
    {

        public List<Carta_Local> ObtenerCartaLocalRestaurante(int intLocal)
        {
            string strdata = "/" + intLocal;
            HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create("http://localhost:49781/Services/CartaLocales.svc/OCartaLocalRestaurante" + strdata);
            httpReq.Method = "POST";
            httpReq.ContentType = "application/json";

            var Resrp = (HttpWebResponse)httpReq.GetResponse();
            StreamReader strread = new StreamReader(Resrp.GetResponseStream());
            string strJson = strread.ReadToEnd();

            JavaScriptSerializer js = new JavaScriptSerializer();
            List<Carta_Local> objCartaLocal = js.Deserialize<List<Carta_Local>>(strJson);
            
            if (objCartaLocal != null) 
            {
                foreach (Carta_Local cl in objCartaLocal)
                {
                    cl.local = (new ModelLocal()).ObtenerLocal(cl.intCodLocal + "");
                    cl.plato = (new ModelPlato()).ObtenerPlato(cl.intCodPlato);
                }
            }

            return objCartaLocal;            
        }

        public void EliminarCartaLocal(int intCartaLocal)
        { 
            
        }

        public Carta_Local ObtenerCartaLocal(int intCartaLocal)
        {
            string strdata = "/" + intCartaLocal;
            HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create("http://localhost:49781/Services/CartaLocales.svc/OCartaLocal" + strdata);
            httpReq.Method = "POST";
            httpReq.ContentType = "application/json";

            var Resrp = (HttpWebResponse)httpReq.GetResponse();
            StreamReader strread = new StreamReader(Resrp.GetResponseStream());
            string strJson = strread.ReadToEnd();

            JavaScriptSerializer js = new JavaScriptSerializer();
            Carta_Local objCartaLocal = js.Deserialize<Carta_Local>(strJson);

            return objCartaLocal;
        }
        
        public void Dispose()
        {
            
        }
 
    }

}